<?php
namespace Admin\Controller;
use Think\Controller;
/**
* 用户管理
*/
class UserController extends Controller{
	public $user;
	public function __construct(){
		parent::__construct();
        if ($_COOKIE['adminname'] == NULL) {
            $this->error('请登录','/bookManage/admin/index/login',1);
        }
		$this->user = D('user');
	}

	//用户登记
	public function addUser(){
		if (IS_POST) {
			$_POST['addtime'] = time();
			if ($this->user->create()) {
				if ($this->user->add(I('post.'))) {
					$this->redirect('user/adduser');
				}else{
					$this->error($this->user->getError());
				}
			}else{
				$this->error($this->user->getError());
			}
		}
		$this->display();
	}

	//用户列表查询
	public function listUser(){
		$this->assign('listuser',$this->user->order('addtime desc')->select());
		$this->display();
	}

	//删除用户
	public function delUser(){
		if ($this->user->delete(I('get.id'))) {
			$this->redirect('user/listuser');
		}else{
			$this->error($this->user->getError());
		}
	}
}